package leetcode.code1665;

import java.util.Arrays;

import leetcode.IDebug;
import leetcode.helper.HelpDebug;

public class Solution implements IDebug {

	public int minimumEffort(int[][] tasks) {
		Arrays.sort(tasks, (a, b) -> a[1] - a[0] == b[1] - b[0] ? b[1] - a[1] : b[1] - b[0] - a[1] + a[0]);
		// [[10, 12], [2, 4], [1, 3], [10, 11], [8, 9]]
		int len = tasks.length;
		int ans = tasks[len - 1][1];
		for (int i = len - 2; i >= 0; i--) {
			ans += ans + tasks[i][0] > tasks[i][1] ? tasks[i][0] : tasks[i][1];
		}
		return ans;
	}

	@Override
	public void debug4() {
		HelpDebug.compare(32, this.minimumEffort(HelpDebug.str2array1("[[1,3],[2,4],[10,11],[10,12],[8,9]]")));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
